package cn.ztuo.bitrade.controller;

import cn.ztuo.bitrade.entity.Member;
import cn.ztuo.bitrade.entity.transform.AuthMember;
import cn.ztuo.bitrade.service.AnswerTopicService;
import cn.ztuo.bitrade.service.MemberService;
import cn.ztuo.bitrade.util.MessageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import static cn.ztuo.bitrade.constant.SysConstant.SESSION_MEMBER;

/**
 * @author: Xiazt
 * @date: 2020-04-22 11:52
 */
@RestController
@RequestMapping("answerTopic")
public class AnswerTopicController extends BaseController {

    @Autowired
    private AnswerTopicService answerTopicService;

    @Autowired
    private MemberService memberService;

    /**
     * 获取所有题目
     *
     * @return
     */
    @RequestMapping("getAll")
    public MessageResult getAll() {
        return success(answerTopicService.findAll());
    }

    /**
     * 答题完成
     *
     * @param user
     * @return
     */
    @RequestMapping("answerFinish")
    public MessageResult answerFinish(@SessionAttribute(SESSION_MEMBER) AuthMember user) {
        Member member = memberService.findOne(user.getId());
        member.setAnswerFinish(1);
        memberService.save(member);
        return success("答题完成！");
    }

}
